/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.saar.penguin.give.dummyserver;

import give.comm.ClientMetadata;
import give.formula.Atom;
import give.formula.Formula;
import give.formula.Orientation;
import give.formula.Position;
import give.nlgserver.NlgServerInstance;
import give.nlgserver.NlgSystem;
import give.nlgserver.discretize.Discretizer;
import give.questionnaire.QuestionnaireData;
import give.world.World;
import java.util.Map;
import java.util.List;

/**
 *
 * @author koller
 */
public class DummyNlgSystem extends NlgSystem {
    // You MUST have a constructor like this, otherwise the NLG system won't
    // be loaded by the NLG server.
    public DummyNlgSystem(NlgServerInstance inst, World world, Discretizer discretizer) {
        super(inst, world, discretizer);
    }

    @Override
    public void connectionDisconnected() {
        // nothing to clean up
    }

    @Override
    public void connectionEstablished(QuestionnaireData preQuestionnaire, ClientMetadata clientMetadata) {
        new Thread() {
            @Override
            public void run() {
                waitfor(500);

                send("Welcome to GIVE! This is the dummy NLG system.");
                waitfor(2500);

                send("Our task is to get a trophy from a safe.  In order to do this, we'll have to turn off the alarm, move the picture, and open the safe.");
                waitfor(4000);

                send("I will show you how to get started.  Turn left, walk up to the button, and click on it.");
                logReferenceAttempt("b1");
            }
        }.start();
    }

    @Override
    public void handleAction(Atom actionInstance, List<Formula> updates) {
        if( actionInstance.getPredicate().equals("manipulate") && actionInstance.getArgumentAsString(0).equals("b1") ) {
            send("Excellent! Now walk through the door. After that, you're on your own.");
        }
    }

    @Override
    public void handleStatusInformation(Position position, Orientation orientation, List<String> visibleObjects) {
        // ignore status updates

    }

    @Override
    public void handleDidNotUnderstand() {
        // ignore misunderstandings

    }

    @Override
    public void handleExternalEvent(String sourceName, Map<String, String> data)  {
        // ignore external events
    }

    private void waitfor(int ms) {
        try {
            Thread.sleep(ms);
        } catch(InterruptedException e) {

        }
    }

}
